package com.oa.order.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import com.fasterxml.jackson.annotation.JsonFormat;

@Entity
@Table(name = "t_order")
public class Order implements Serializable {

	// 业务数据字段
	private Long orderId;
	private int dinner;
	private int nightSnack;
	private int breakfast;
	private int lunch;
	private Date applyTime;
	private String state;
	private String approver;
	private Date approvalTime;
	private String refuseReason;

	private Long userId;
	private String userName;
	private Long department;
	private String departmentName;

	// 工作流程数据字段
	// 流程实例Id：用于关联下列临时数据
	private String processInstanceId; // 没有启动流程之前为""

	// -- 临时属性 @Transient 不会被保存到当前实体的OA_LEAVE表，用于临时存储流程数据，目的是让工作流数据与业务数据结合--//

	private Task task;// 流程任务

	private Map<String, Object> variables;// 流程变量

	// 运行中的流程实例
	private ProcessInstance processInstance;

	// 历史的流程实例
	private HistoricProcessInstance historicProcessInstance;

	// 流程定义
	private ProcessDefinition processDefinition;

	public String getUserName() {
		return userName;
	}

	public Long getUserId() {
		return userId;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getOrderId() {
		return orderId;
	}

	@Column
	public Long getDepartment() {
		return department;
	}

	@Column
	public int getDinner() {
		return dinner;
	}

	@Column
	public int getNightSnack() {
		return nightSnack;
	}

	@Column
	public int getBreakfast() {
		return breakfast;
	}

	@Column
	public int getLunch() {
		return lunch;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "apply_time")
	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public Date getApplyTime() {
		return applyTime;
	}

	@Column
	public String getState() {
		return state;
	}

	@Column
	public String getApprover() {
		return approver;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "approval_time")
	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public Date getApprovalTime() {
		return approvalTime;
	}

	public String getDepartmentName() {
		return departmentName;
	}

	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}

	public void setDepartment(Long department) {

		this.department = department;
	}

	public void setDinner(int dinner) {
		this.dinner = dinner;
	}

	public void setNightSnack(int nightSnack) {
		this.nightSnack = nightSnack;
	}

	public void setBreakfast(int breakfast) {
		this.breakfast = breakfast;
	}

	public void setLunch(int lunch) {
		this.lunch = lunch;
	}

	public void setApplyTime(Date applyTime) {
		this.applyTime = applyTime;
	}

	public void setState(String state) {
		this.state = state;
	}

	public void setApprover(String approver) {
		this.approver = approver;
	}

	public void setApprovalTime(Date approvalTime) {
		this.approvalTime = approvalTime;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Column
	public String getProcessInstanceId() {
		return processInstanceId;
	}

	@Transient
	public Task getTask() {
		return task;
	}

	@Transient
	public Map<String, Object> getVariables() {
		return variables;
	}

	@Transient
	public ProcessInstance getProcessInstance() {
		return processInstance;
	}

	@Transient
	public HistoricProcessInstance getHistoricProcessInstance() {
		return historicProcessInstance;
	}

	@Transient
	public ProcessDefinition getProcessDefinition() {
		return processDefinition;
	}

	public void setProcessInstanceId(String processInstanceId) {
		this.processInstanceId = processInstanceId;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public void setVariables(Map<String, Object> variables) {
		this.variables = variables;
	}

	public void setProcessInstance(ProcessInstance processInstance) {
		this.processInstance = processInstance;
	}

	public void setHistoricProcessInstance(HistoricProcessInstance historicProcessInstance) {
		this.historicProcessInstance = historicProcessInstance;
	}

	public void setProcessDefinition(ProcessDefinition processDefinition) {
		this.processDefinition = processDefinition;
	}

	public Order(Long orderId, int dinner, int nightSnack, int breakfast, int lunch, Date applyTime, String state,
			String approver, Date approvalTime, Long userId, String userName, Long department) {
		super();
		this.orderId = orderId;
		this.dinner = dinner;
		this.nightSnack = nightSnack;
		this.breakfast = breakfast;
		this.lunch = lunch;
		this.applyTime = applyTime;
		this.state = state;
		this.approver = approver;
		this.approvalTime = approvalTime;
		this.userId = userId;
		this.userName = userName;
		this.department = department;
	}

	public Order() {
	}

	public String getRefuseReason() {
		return refuseReason;
	}

	public void setRefuseReason(String refuseReason) {
		this.refuseReason = refuseReason;
	}

}
